package com.google.coffeeshop.gui.desktop.statistics;

import static net.sf.dynamicreports.report.builder.DynamicReports.*;

import java.util.Date;

import vn.bang.utility.DateUtil;

import com.google.coffeeshop.business.StatisticsBusiness;

import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import net.sf.dynamicreports.report.builder.chart.Bar3DChartBuilder;
import net.sf.dynamicreports.report.builder.column.TextColumnBuilder;
import net.sf.dynamicreports.report.builder.style.FontBuilder;
import net.sf.dynamicreports.report.constant.Orientation;
import net.sf.dynamicreports.report.exception.DRException;


public class ExportDesign {
	public Long productId =null;
	public Date beginDate;
	public Date endDate;
	public JasperReportBuilder build() throws DRException {
		JasperReportBuilder report = report();
		//init styles
		FontBuilder  boldFont = stl.fontArialBold();

		//init columns

		TextColumnBuilder<String> codeColumn = col.column("Code", "code", type.stringType());
		TextColumnBuilder<String> nameColumn = col.column("Name", "name", type.stringType());
		TextColumnBuilder<Long> soldColumn = col.column("Sold Quantity", "inventory", type.longType());		
		//init groups
		//ColumnGroupBuilder productGroup = grp.group(groupColumn);

		//init subtotals
		
		//init charts
		Bar3DChartBuilder itemChart = cht.bar3DChart()
			.setTitle("Sold quantity by product")
			.setTitleFont(boldFont)
			.setOrientation(Orientation.VERTICAL)
			.setCategory(nameColumn)
			
			.addSerie(
				cht.serie(soldColumn));
			
		//configure report
		report
			.setTemplate(Templates.reportTemplate)
			//columns
			.columns(
				codeColumn, nameColumn, soldColumn)
			//groups
			//.groupBy(productGroup)
			//subtotals
			
			//band components
			.title(
				Templates.createTitleComponent("Sold quantity "+ DateUtil.toString(beginDate) + " - " + DateUtil.toString(endDate)),	
					itemChart)
			.pageFooter(
				Templates.footerComponent)
			.setDataSource(StatisticsBusiness.getProductsSoldBetweenDates(productId, beginDate, endDate));

		return report;
	}

	
}